'use strict';
const path = require('path');
/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1597911268814_911';

  // add your middleware config here
  config.middleware = [];

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };
  exports.security = {
    // 前后端分离，post请求不方便携带_csrf
    csrf: {
      enable: false,
    },
  };

  // 配置模板
  exports.view = {
    // 默认模板引擎
    defaultViewEngine: 'nunjucks',
    // 默认模板扩展名
    defaultExtension: '.html',
    // mapping: {
    //   '.html': 'nunjucks',
    // },
  };

  // 设置session
  exports.session = {
    key: 'EGG_SESS:SHENGBANG',
    maxAge: 60 * 1000, // 60 s
    httpOnly: true, // 前端不能修改，默认就是true
    encrypt: true, // 加密传输
    prefix: 'weibo:sess:', // redis存储时的key前缀
  };

  // 配置redis
  exports.redis = {
    client: {
      host: 'localhost',
      port: '6379',
      password: '',
      db: '0',
    },
    agent: true,
  };

  // 配置sequelize
  exports.sequelize = {
    dialect: 'mysql',
    host: 'localhost',
    port: '3306',
    username: 'root',
    password: 'root',
    database: 'egg-weibo',
  };
  // 设置静态文件目录
  config.static = {
    prefix: '/', // 访问路径
    dir: path.join(appInfo.baseDir, 'app/public'), // 设置静态文件目录
  };

  // 配置ajv
  config.ajv = {
    keyword: 'schema', // to indicate the namespace and path of schemas, default as 'schema'
    allErrors: true, // required for custom error message
    jsonPointers: true, // required for custom error message
  };

  return {
    ...config,
    ...userConfig,
  };
};
